*********************************************************************************************
*********************************************************************************************
*********     REPLICATION FOR:                                                ***************
*********     RISE OF GRASSROOTS CIVIL SOCIETY IN ONE-PARTY RULE              ***************
*********************************************************************************************
*********************************************************************************************

* Authors: 
*   
*   Yu Zeng (Asst. Prof, School of Government, Peking University)
*   Junyan Jiang (Asst. Prof, Dept of Political Science, Columbia University)
*   Jie Li (PhD candidate, Department of East Asian Studies, University of Vienna)
*   Christian Goebel (University Professor of Modern China Studies, Department of East Asian Studies, University of Vienna)

* Version: 1.0
* Tested under:
** Stata 16.0 SE
** Environment: Windows 11 x64, Intel i9-9980HK CPU, 32GB RAM


use replication_data, clear
sort cityid year

*****************************
// Table 4: Effect of Pro-HoA Policies on Homeowners’ Complaints

eststo clear
eststo m1: reghdfe F.homeownersCompltPct policyHome if year>=2009, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m2: reghdfe F.homeownersCompltPct policyHome loggdppc logpropprice provPolicy if year>=2009, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"
estadd local cov "\(\checkmark\)"

esttab m* using mechpolicy.txt, nogaps nonote nobaselevels b(4) se(4) ///
 star(* 0.1 ** 0.05 *** 0.01) label booktabs replace  ///
 keep(policyHome loggdppc logpropprice provPolicy) ///
 order(policyHome loggdppc logpropprice provPolicy) ///
 nomtitles mgroup("DV: \% homeowners' complaint next year (t+1)", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
 stats(fe r2_a N_clust N, labels("City and year fixed effects" "Adjusted R square" "Number of cities" "Observations") fmt(0 2 0 0) )

 
 
*****************************
*****************************
**** Appendix 

****** Table A.3 Validating the Measure of Homeowners’ Complaint with Protest Data    ******

capture drop logrealestateprotest logrealprotest_original
g logrealestateprotest = log(realestateprotest+1)
g logrealprotest_original = log(realprotest_original+1)

eststo clear
eststo m1: reg logrealestateprotest logHomeownersComplt, cluster(cityid)

eststo m2: reg logrealestateprotest logHomeownersComplt loggdp logpop, cluster(cityid)
estadd local cov "\(\checkmark\)"

eststo m3: reghdfe logrealestateprotest logHomeownersComplt loggdp logpop, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"
estadd local cov "\(\checkmark\)"

esttab m*  using inv_valid_A3.txt, nonote nobaselevels keep(logHomeownersComplt) b(4) se(4) nomtitles ///
 star(* 0.1 ** 0.05 *** 0.01) label booktabs replace   ///
mgroup("DV: Log Homeowner Protest (Wickedonna)", pattern(1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(fe cov r2_a N_clust N, labels( "Covariates" "City and year fixed effects" "Adjusted R square" "Number of cities"  "Observations") fmt(0 0 2 0 0) )


****** Table A.4 Validating the Measure of Homeowners’ Complaints with Web Search Data (Baidu Index)    ******

capture drop homesearch_total log_homesearch_total
egen homesearch_total = rowtotal(baiduindex_hoacondition baiduindex_hoaguideline baiduindex_hoarule baiduindex_homebylaw baiduindex_homecommittee baiduindex_homeconvenant baiduindex_pmr baiduindex_proeprtyfee baiduindex_propertycompany baiduindex_propertylaw baiduindex_propertymgt baiduindex_propertyservice)
label variable homesearch_total "Total search volume of property-related keywords"
g log_homesearch_total = log(homesearch_total+1)
label variable log_homesearch_total "Log total search volume of property-related keywords"
sum log_homesearch_total

eststo clear
eststo m1: reg log_homesearch_total logHomeownersComplt, cluster(cityid)

eststo m2: reg log_homesearch_total logHomeownersComplt loggdp logpop, cluster(cityid)
estadd local cov "\(\checkmark\)"

eststo m3: reghdfe log_homesearch_total logHomeownersComplt loggdp logpop, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"
estadd local cov "\(\checkmark\)"

esttab m* using inv_valid_A4.txt, nogaps nonote nobaselevels b(4) se(4) ///
 star(* 0.1 ** 0.05 *** 0.01) label booktabs replace  ///
 keep(logHomeownersComplt) ///
 order(logHomeownersComplt) ///
 nomtitles mgroup("DV: Log search volume of keywords", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
 stats(cov fe r2_a N_clust N, labels("Covariates" "City and year fixed effects" "Adjusted R square" "Number of cities" "Observations") fmt(0 0 2 0 0) )


****** Table A.13 Testing Exclusion Restrictions of the IV Design   ******

eststo clear

eststo m1: reghdfe loggdppc diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

capture drop gdp g_gdp
g gdp = exp(loggdp)
by cityid: g g_gdp = 1-gdp[_n-1]/gdp[_n]
eststo m2: reghdfe g_gdp diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m3: reghdfe logpop diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m4: reghdfe urbanrate diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m5: reghdfe urbanrate_pop diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m6: reghdfe logpropprice diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m7: reghdfe noiseCompltPct diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

eststo m8: reghdfe landCompltPct diffleaderXL5loglandrev_rev if year>2007 & year<2018, a(cityid year) cluster(cityid)
estadd local fe "\(\checkmark\)"

esttab m* using exclusion.txt, nogaps nonote nobaselevels b(3) se(3) ///
 star(* 0.1 ** 0.05 *** 0.01) label booktabs replace  ///
 keep(diffleaderXL5loglandrev_rev) ///
 order(diffleaderXL5loglandrev_rev) ///
 mtitles("Log GDP per capita" "GDP growth rate" "Log population" "Urban rate (\% area)" "Urban rate (\% population)" "Log property price" "\% noise complaint" "\% land complaint" ) ///
 mgroup("DV", pattern(1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
 stats(fe r2_a N_clust N, labels("City and year fixed effects" "Adjusted R square" "Number of cities" "Observations") fmt(0 2 0 0) )
 

